<!DOCTYPE html>
<html lang="en">
	<head>
		<title>three.js webgl - AMF</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
		<style>
			body {
				font-family: Monospace;
				background-color: #000000;
				margin: 0px;
				overflow: hidden;
			}

			#info {
				color: #fff;
				position: absolute;
				top: 10px;
				width: 100%;
				text-align: center;
				z-index: 100;
				display:block;

			}

			a { color: skyblue }
			.button { background:#999; color:#eee; padding:0.2em 0.5em; cursor:pointer }
			.highlight { background:orange; color:#fff; }

			span {
				display: inline-block;
				width: 60px;
				float: left;
				text-align: center;
			}

		</style>
	</head>
	<body>
		<div id="info">
			<a href="http://threejs.org" target="_blank">three.js</a>
			<a href="http://amf.wikispaces.com" target="_blank">AMF File format</a>
			<div>AMF loader test by <a href="https://github.com/tamarintech" target="_blank">tamarintech</a></div>
			<div>Rook manufacturing file from <a href="http://amf.wikispaces.com/AMF+test+files" target="_blank">AMF test files</a></div>
		</div>

		<script src="../build/three.js"></script>
		<script src="js/loaders/AMFLoader.js"></script>

		<script src="js/Detector.js"></script>
		<script src="js/controls/OrbitControls.js"></script>

		<script>

			if ( ! Detector.webgl ) Detector.addGetWebGLMessage();

			var camera, scene, renderer;

			init();

			function init() {

				scene = new THREE.Scene();
				scene.add( new THREE.AmbientLight( 0x999999 ) );

				camera = new THREE.PerspectiveCamera( 35, window.innerWidth / window.innerHeight, 1, 500 );

				// Z is up for objects intended to be 3D printed.

				camera.up.set( 0, 0, 1 );
				camera.position.set( 0, -9, 6 );

				camera.add( new THREE.PointLight( 0xffffff, 0.8 ) );

				scene.add( camera );

				var grid = new THREE.GridHelper( 50, 50, 0xffffff, 0x555555 );
				grid.rotateOnAxis( new THREE.Vector3( 1, 0, 0 ), 90 * ( Math.PI/180 ) );
				scene.add( grid );

				renderer = new THREE.WebGLRenderer( { antialias: true } );
				renderer.setClearColor( 0x999999 );
				renderer.setPixelRatio( window.devicePixelRatio );
				renderer.setSize( window.innerWidth, window.innerHeight );
				document.body.appendChild( renderer.domElement );

				var loader = new THREE.AMFLoader();
				loader.load( './models/amf/rook.amf', function ( amfobject ) {

					scene.add( amfobject );
					render();

				} );

				var controls = new THREE.OrbitControls( camera, renderer.domElement );
				controls.addEventListener( 'change', render );
				controls.target.set( 0, 1.2, 2 );
				controls.update();

				window.addEventListener( 'resize', onWindowResize, false );

			}

			function onWindowResize() {

				camera.aspect = window.innerWidth / window.innerHeight;
				camera.updateProjectionMatrix();

				renderer.setSize( window.innerWidth, window.innerHeight );

				render();

			}

			function render() {

				renderer.render( scene, camera );

			}

		</script>
	</body>
</html>
